const main = async function(ctx) {
    //const tmpdir = os.tmpdir(); //返回系统临时文件

    const tmpdir = path.join(__dirname, "public/images");

    const filePaths = [];
    const files = ctx.request.files || {};
    const params = ctx.request.body
    console.log(params);
    for (let key in files) {
        const file = files[key];
        if(Object.prototype.toString.call(file) == '[object Array]'){
            for(var j = 0; j < file.length; j++ ){
                witeFile(file[j]);
            }
        }else{
            witeFile(file);

        }
    }
    function witeFile(file){
        const filePath = path.join(tmpdir, file.name);
        const reader = fs.createReadStream(file.path);
        const writer = fs.createWriteStream(filePath);
        reader.pipe(writer);
        filePaths.push(filePath);
    }

    ctx.body = filePaths;
};

module.exports = main
